package com.qzsoft.zhjd.laboratory.modules.tensionResult.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.laboratory.modules.tensionRecording.entity.TensionRecording;
import com.qzsoft.zhjd.laboratory.modules.tensionResult.entity.TensionResult;
import com.qzsoft.zhjd.laboratory.modules.tensionResult.service.TensionResultService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 张拉结果(TensionResult)表控制层
 *
 * @author makejava
 * @since 2023-07-12 14:24:02
 */
@RestController
@AllArgsConstructor
@RequestMapping("/laboratory/tensionResult")
public class TensionResultController extends ApiController {

    private TensionResultService tensionResultService;

    /**
     * 分页
     *
     * @param params 查询条件
     * @return Result 分页列表
     */
    @GetMapping("page")
    public Result<IPage<TensionResult>> page(@RequestParam Map<String, Object> params) {
        IPage<TensionResult> page = tensionResultService.page(params);
        return ResultUtils.ok(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("find/{id}")
    public Result selectOne(@PathVariable("id") String id) {
        return ResultUtils.ok(tensionResultService.getInfoById(id));
    }

    /**
     * 新增数据
     *
     * @param tensionResult 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody TensionResult tensionResult) {
//        if(tensionResult.getCode()!=null){
//            QueryWrapper<TensionResult> queryWrapper = new QueryWrapper<TensionResult>();
//            queryWrapper.eq("code",tensionResult.getCode());
//            queryWrapper.eq("link_code",tensionResult.getLinkCode());
//            List<TensionResult>  result = tensionResultService.list(queryWrapper);
//            if(result.size()==0){
//                tensionResultService.insertTensionResult(tensionResult);
//            }
//        }else{
//            tensionResultService.insertTensionResult(tensionResult);
//        }
        tensionResultService.insertTensionResult(tensionResult);
        return ResultUtils.ok();
    }

    /**
     * 修改数据
     *
     * @param tensionResult 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateTensionResult")
    public Result update(@RequestBody TensionResult tensionResult) {
        tensionResultService.updateTensionResult(tensionResult);
        return ResultUtils.ok();
    }

    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/deleteByIds")
    public Result delete(@RequestBody String[] ids) {
        tensionResultService.deleteByIds(Arrays.asList(ids));
        return ResultUtils.ok();
    }
}

